﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>@ViewBag.Title</title>
    <link href="~/Scripts/jquery-easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Scripts/jquery-easyui/themes/icon-extension.css" rel="stylesheet" />
    <link href="~/Scripts/jquery-easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Scripts/jquery-easyui/themes/custom.css" rel="stylesheet" />
    @RenderSection("Style", false)
</head>
<body class="easyui-layout">
    <!--  layout  -->
    @RenderBody()
    <div data-options="region:'center'">
        <div id="tabs" class="easyui-tabs" data-options="fit:true,border:false,
             tools:[
                    {iconCls : 'icon-reload',handler:refreshCurrentTab},
                    {iconCls : 'icon-cancel',handler:closeTab}
             ]">
            <div title="欢迎使用" style="padding: 20px; overflow: hidden;" id="home" data-options="iconCls:'icon-home'">
                <h1>
                    欢迎使用系统
                </h1>
            </div>
        </div>
    </div>
    <div data-options="region:'south'" class="footer">
        <div class="footer-left">@ViewBag.FooterLeftMessage</div>
        <div class="footer-center">@ViewBag.FooterCenterMessage</div>
        <div class="footer-right">@ViewBag.FooterRightMessage</div>
    </div>
    <!--  /layout  -->
    <!--  tabRightMenu  -->
    <div id="mm" class="easyui-menu" style="width: 150px;">
        <div id="refresh">
            刷新
        </div>
        <div class="menu-sep">
        </div>
        <div id="close">
            关闭
        </div>
        <div id="closeall">
            关闭全部
        </div>
        <div id="closeother">
            关闭其他
        </div>
        <div class="menu-sep">
        </div>
        <div id="closeright">
            关闭右侧
        </div>
        <div id="closeleft">
            关闭左侧
        </div>
    </div>
    <!--  /tabRightMenu  -->
    <!--  indow  -->
    <div id="winChangePassword" class="easyui-dialog" title="修改密码" style="width: 310px; overflow: hidden" data-options="
                closed:true,
                modal:true,
                iconCls: 'icon-save',
                toolbar: [{
                    text:'保存',
                    iconCls:'icon-save',
                    handler:savePassword
                }]
            ">
        <div class="willow-form" style="width: 295px;">
            <fieldset>
                <form id="fm" class="easyui-form" method="post">
                    <table class="table2column">
                        <tr>
                            <th>
                                原密码：
                            </th>
                            <td>
                                <input type="password" id="oldPassword" name="oldPassword" class="easyui-validatebox" data-options="required:true" />
                            </td>
                        </tr>
                        <tr>
                            <th>
                                新密码：
                            </th>
                            <td>
                                <input type="password" id="newPassword" name="newPassword" class="easyui-validatebox" data-options="required:true" />
                            </td>
                        </tr>
                    </table>
                </form>
            </fieldset>
        </div>
    </div>
    <!--  /indow  -->
    <script src="~/Scripts/jquery-2.0.3.min.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.min.custom.js"></script>
    <script src="~/Scripts/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
    <script src="~/Scripts/jquery-easyui/jquery.easyui.extension.js"></script>
    <script src="~/Scripts/willow/willow.common.js"></script>
    <script>
        $(function () {
            initTab();
            keepAlive();
        });

        //保持在线
        function keepAlive() {
            setInterval(function () {
                var timestamp = (new Date()).valueOf();
                $.get('@Url.Action("KeepAlive")?v=' + timestamp);
            }, 30 * 1000)
        }


        //注销
        function logout() {
            $.messager.confirm('信息提示', '确定退出系统吗?', function (r) {
                if (r) {
                    location.href = '@Url.Action("Logout")';
                }
            });
        }

        //打开修改密码窗口
        function openChangePassword() {
            $('#fm').form('clear');
            $('#winChangePassword').dialog('open');
        }

        //保存密码
        function savePassword() {
            var isValid = $('#fm').form('validate');
            if (!isValid) {
                return false;
            }

            var postData = {
                oldPassword: $('#oldPassword').val(),
                newPassword: $('#newPassword').val()
            };
            var url = '@Url.Action("ChangePassword")';
            common.post(url, postData, function (result) {
                if (result) {
                    $('#winChangePassword').dialog('close');
                }
            });
        }

        //添加标签
        function addTab(title, url, iconCls) {

            iconCls = iconCls || 'icon-home';

            if ($('#tabs').tabs('exists', title)) {
                $('#tabs').tabs('select', title);
            } else {
                $('#tabs').tabs('add', {
                    title: title,
                    content: createFrame(url),
                    closable: true,
                    iconCls: iconCls
                });
            }

        }

        //创建frame
        function createFrame(url) {
            var s = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:99.5%;"></iframe>';
            return s;
        }

        //关闭标签
        function closeTab() {
            var currentTab = $('#tabs').tabs('getSelected');
            currentTitle = currentTab.panel('options').title;
            if (currentTab.panel('options').closable) {
                $('#tabs').tabs('close', currentTitle);
            }
        }

        //刷新标签
        function refreshTab(title) {
            var refreshTab = $('#tabs').tabs('getTab', title);
            /*获取选中的标签项*/
            var url = $(refreshTab.panel('options').content).attr('src');
            if (!url) {
                return false;
            }
            $('#tabs').tabs('update', {
                tab: refreshTab,
                options: {
                    content: createFrame(url)
                }
            })
        }

        //刷新当前标签
        function refreshCurrentTab() {
            var title = $('#tabs').tabs('getSelected').panel('options').title;
            var refreshTab = $('#tabs').tabs('getTab', title);
            /*获取选中的标签项*/
            var url = $(refreshTab.panel('options').content).attr('src');
            if (!url) {
                return false;
            }
            $('#tabs').tabs('update', {
                tab: refreshTab,
                options: {
                    content: createFrame(url)
                }
            })
        }

        /*点击修改密码*/
        function onclickChangePassword() {
            $('#win').window('open');
        }

        /*修改密码-点击保存*/
        function onclickSavePassword() {
            var url = "@Url.Action("ChangePassowrd", "User", new { area = "System" })";
            var data = {
                originalPassword: $("#OriginalPassword").val(),
                newPassword: $("#NewPassword").val()
            }
            $.post(url, data, function (data) {
                if (data.result) {
                    $.messager.alert('信息提示', '保存成功', 'info', function () {
                        $('#win').window('close');
                    });
                } else {
                    $.messager.alert('信息提示', '保存失败', 'info');
                }
            }, 'json');
        }

        //初始化标签
        function initTab() {

            $('#tabs').tabs({
                onContextMenu: function (e, node) {
                    e.preventDefault();
                    $('#tabs').tabs('select', node);
                    // 显示上下文菜单
                    $('#mm').menu('show', {
                        left: e.pageX,
                        top: e.pageY
                    });
                }
            });

            $('#mm').menu({
                onClick: function (item) {
                    tabClick(item.id);
                }
            });

            return false;
        }

        //标签右击事件
        function tabClick(action) {
            var alltabs = $('#tabs').tabs('tabs');
            var currentTab = $('#tabs').tabs('getSelected');
            var allTabtitle = [];
            $.each(alltabs, function (i, n) {
                var data = {
                    title: $(n).panel('options').title,
                    closable: $(n).panel('options').closable
                }
                allTabtitle.push(data);
            })
            switch (action) {
                case "refresh":
                    var iframe = $(currentTab.panel('options').content);
                    var src = iframe.attr('src');
                    $('#tabs').tabs('update', {
                        tab: currentTab,
                        options: {
                            content: createFrame(src)
                        }
                    })
                    break;
                case "close":
                    var currtab_title = currentTab.panel('options').title;
                    var currtab_closable = currentTab.panel('options').closable;
                    if (currtab_closable) {
                        $('#tabs').tabs('close', currtab_title);
                    }
                    break;
                case "closeall":
                    $.each(allTabtitle, function (i, n) {
                        if (n.closable) {
                            $('#tabs').tabs('close', n.title);
                        }
                    });

                    break;
                case "closeother":
                    var currtab_title = currentTab.panel('options').title;
                    $.each(allTabtitle, function (i, n) {
                        if (n.title != currtab_title && n.closable) {
                            $('#tabs').tabs('close', n.title);
                        }
                    });
                    break;
                case "closeright":
                    var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);

                    if (tabIndex == alltabs.length - 1) {
                        return false;
                    }
                    $.each(allTabtitle, function (i, n) {
                        if (i > tabIndex) {
                            if (n.closable) {
                                $('#tabs').tabs('close', n.title);
                            }
                        }
                    });

                    break;
                case "closeleft":
                    var tabIndex = $('#tabs').tabs('getTabIndex', currentTab);
                    if (tabIndex == 1) {
                        return false;
                    }
                    $.each(allTabtitle, function (i, n) {
                        if (i < tabIndex) {
                            if (n.closable) {
                                $('#tabs').tabs('close', n.title);
                            }
                        }
                    });

                    break;
            }
        }

        function showWarning(msg, title) {
            title = title || '信息提示';
            msg = '<div class="messager-icon messager-error"></div>' + msg;
            $.messager.show({
                title: title,
                msg: msg,
                timeout: 2000,
                style: {
                    right: '',
                    top: document.body.scrollTop + document.documentElement.scrollTop,
                    bottom: ''
                }
            });
        }

        //显示提示信息
        function showAlert(msg, icon, title) {
            title = title || '信息提示';
            var content = '<div>' + msg + '</div>';
            switch (icon) {
                case 'error':
                    content = '<div class="messager-icon messager-error"></div>' + content;
                    break;
                case 'info':
                    content = '<div class="messager-icon messager-info"></div>' + content;
                    break;
                case 'question':
                    content = '<div class="messager-icon messager-question"></div>' + content;
                    break;
                case 'warning':
                    content = '<div class="messager-icon messager-warning"></div>' + content;
                    break;
            }
            msg = '<div class="messager-icon messager-info"></div>' + msg;
            $.messager.show({
                title: title,
                msg: content,
                timeout: 2000,
                style: {
                    right: '',
                    top: document.body.scrollTop + document.documentElement.scrollTop,
                    bottom: ''
                }
            });
        }

    </script>
    @RenderSection("Script", false)
</body>
</html>